<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout/default}">
<head>
    <title>编辑用户</title>
</head>
<body>
    <div layout:fragment="content" class="fade-in">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2><i class="fas fa-user-edit me-2"></i>编辑用户</h2>
            <div>
                <a th:href="@{/admin/users/{id}(id=${user.id})}" class="btn btn-secondary me-2">
                    <i class="fas fa-arrow-left me-2"></i>返回用户详情
                </a>
                <a href="/admin/users" class="btn btn-secondary">
                    <i class="fas fa-users me-2"></i>返回用户列表
                </a>
            </div>
        </div>
        
        <div class="card">
            <div class="card-body">
                <form th:action="@{/admin/users/{id}/edit(id=${user.id})}" method="post">
                    <div class="mb-3">
                        <label for="username" class="form-label">用户名</label>
                        <input type="text" class="form-control" id="username" name="username" th:value="${user.username}" required>
                    </div>
                    
                    <div class="mb-3">
                        <label for="email" class="form-label">电子邮箱</label>
                        <input type="email" class="form-control" id="email" name="email" th:value="${user.email}" required>
                    </div>
                    
                    <div class="mb-3">
                        <label for="role" class="form-label">用户角色</label>
                        <select class="form-select" id="role" name="role" required>
                            <option th:each="roleOption : ${roles}" 
                                    th:value="${roleOption}" 
                                    th:text="${roleOption.name() == 'ADMIN' ? '管理员' : '普通用户'}"
                                    th:selected="${roleOption == user.role}">
                                角色
                            </option>
                        </select>
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label">注册时间</label>
                        <p class="form-control-plaintext" th:text="${#temporals.format(user.createdAt, 'yyyy-MM-dd HH:mm:ss')}">注册时间</p>
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label">最后更新时间</label>
                        <p class="form-control-plaintext" th:text="${user.updatedAt != null ? #temporals.format(user.updatedAt, 'yyyy-MM-dd HH:mm:ss') : '未更新'}">最后更新时间</p>
                    </div>
                    
                    <div class="d-grid gap-2">
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-save me-2"></i>保存更改
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</body>
</html> 